import Vue from 'vue'
import Vuex from 'vuex'


Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: sessionStorage.getItem('token')||'',
    name: sessionStorage.getItem('name') || '',
    avatar: sessionStorage.getItem('avatar') || '',
    // menus: JSON.parse(sessionStorage.getItem('menus')||'[]'),
    // roles: JSON.parse(sessionStorage.getItem('roles')||'[]'),
    // permissions: JSON.parse(sessionStorage.getItem('permissions')||'[]'),
    menus: [],
    roles: [],
    permissions: [],
  },
  mutations: {
    setToken(state, data) {
      state.token = data
      console.log('vuex中的token', data)
      sessionStorage.setItem('token', data);
    },
    setName(state, data) {
      state.name = data;
      sessionStorage.setItem('name', data);
    },
    //用户头像
    setAvatar(state, data) {
      state.avatar = data;
      sessionStorage.setItem('avatar', data);
    },
    setRoles(state, data) {
      state.roles = data;
      // sessionStorage.setItem("roles",JSON.stringify(data))
    },
    setMenus(state, data) {
      state.menus = data;
      // sessionStorage.setItem('menus',data)
    },
    setPermission(state, data) {
      state.permissions = data;
    }
  },
    //用户名
    // setUserName(state, data) {
    //   state.userName = data;
    //   sessionStorage.setItem('userName', JSON.stringify(data));
    // },

    actions: {},
    modules: {}

});

